/*
**    Copyright (C) 2003-2011 Institute for Systems Biology
**                            Seattle, Washington, USA.
**
**    This library is free software; you can redistribute it and/or
**    modify it under the terms of the GNU Lesser General Public
**    License as published by the Free Software Foundation; either
**    version 2.1 of the License, or (at your option) any later version.
**
**    This library is distributed in the hope that it will be useful,
**    but WITHOUT ANY WARRANTY; without even the implied warranty of
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
**    Lesser General Public License for more details.
**
**    You should have received a copy of the GNU Lesser General Public
**    License along with this library; if not, write to the Free Software
**    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
*/

package org.systemsbiology.tsv;

/**
 * Basic implementer of {@link Header}. Hashable.
 * @author trobinso
 */
public class BasicHeader implements Header {
    private static final long serialVersionUID = -251123145579366622L;
    
    String name = null;

    /**
     * Default constructor for BasicHeader
     */
    public BasicHeader() {}

    /**
     * Constructor for BasicHeader, requiring name to be immediately supplied
     * @param name String immediate name for this Header
     */
    public BasicHeader(String name) {
        this.name = name;
    }

    /**
     * @inheritDoc
     */
    public void setName(String name) {
        assert(name != null);

        this.name = name;
    }

    /**
     * @inheritDoc
     */
    public String getName() {
        assert(name != null);

        return name;
    }

    public int compareTo(Header h) {
        assert(this.name != null);

        return this.name.compareTo(h.getName());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        BasicHeader that = (BasicHeader) o;

        if (name != null ? !name.equals(that.name) : that.name != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return name != null ? name.hashCode() : 0;
    }

    @Override
    public String toString() {
        return "BasicHeader{\"" + name + "\"}";
    }
}
